using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
namespace Microsoft.Expression.Drawing.Core
{
	internal static class TransformExtensions
	{
		public static Point TransformPoint(this IEnumerable<GeneralTransform> transforms, Point point)
		{
			if (transforms == null)
			{
				return point;
			}
			using (IEnumerator<GeneralTransform> enumerator = transforms.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					GeneralTransform current = enumerator.get_Current();
					point = GeometryHelper.SafeTransform(current, point);
				}
			}
			return point;
		}
		public static Transform CloneTransform(this Transform transform)
		{
			if (transform == null)
			{
				return null;
			}
			TranslateTransform translateTransform = transform as TranslateTransform;
			if (translateTransform != null)
			{
				TranslateTransform translateTransform2 = new TranslateTransform();
				translateTransform2.set_X(translateTransform.get_X());
				translateTransform2.set_Y(translateTransform.get_Y());
				return translateTransform2;
			}
			RotateTransform rotateTransform = transform as RotateTransform;
			if (rotateTransform != null)
			{
				RotateTransform rotateTransform2 = new RotateTransform();
				rotateTransform2.set_Angle(rotateTransform.get_Angle());
				rotateTransform2.set_CenterX(rotateTransform.get_CenterX());
				rotateTransform2.set_CenterY(rotateTransform.get_CenterY());
				return rotateTransform2;
			}
			ScaleTransform scaleTransform = transform as ScaleTransform;
			if (scaleTransform != null)
			{
				ScaleTransform scaleTransform2 = new ScaleTransform();
				scaleTransform2.set_ScaleX(scaleTransform.get_ScaleX());
				scaleTransform2.set_ScaleY(scaleTransform.get_ScaleY());
				scaleTransform2.set_CenterX(scaleTransform.get_CenterX());
				scaleTransform2.set_CenterY(scaleTransform.get_CenterY());
				return scaleTransform2;
			}
			SkewTransform skewTransform = transform as SkewTransform;
			if (skewTransform != null)
			{
				SkewTransform skewTransform2 = new SkewTransform();
				skewTransform2.set_AngleX(skewTransform.get_AngleX());
				skewTransform2.set_AngleY(skewTransform.get_AngleY());
				skewTransform2.set_CenterX(skewTransform.get_CenterX());
				skewTransform2.set_CenterY(skewTransform.get_CenterY());
				return skewTransform2;
			}
			CompositeTransform compositeTransform = transform as CompositeTransform;
			if (compositeTransform != null)
			{
				CompositeTransform compositeTransform2 = new CompositeTransform();
				compositeTransform2.set_CenterX(compositeTransform.get_CenterX());
				compositeTransform2.set_CenterY(compositeTransform.get_CenterY());
				compositeTransform2.set_Rotation(compositeTransform.get_Rotation());
				compositeTransform2.set_ScaleX(compositeTransform.get_ScaleX());
				compositeTransform2.set_ScaleY(compositeTransform.get_ScaleY());
				compositeTransform2.set_SkewX(compositeTransform.get_SkewX());
				compositeTransform2.set_SkewY(compositeTransform.get_SkewY());
				compositeTransform2.set_TranslateX(compositeTransform.get_TranslateX());
				compositeTransform2.set_TranslateY(compositeTransform.get_TranslateY());
				return compositeTransform2;
			}
			MatrixTransform matrixTransform = transform as MatrixTransform;
			if (matrixTransform != null)
			{
				MatrixTransform matrixTransform2 = new MatrixTransform();
				matrixTransform2.set_Matrix(matrixTransform.get_Matrix());
				return matrixTransform2;
			}
			TransformGroup transformGroup = transform as TransformGroup;
			if (transformGroup != null)
			{
				TransformGroup transformGroup2 = new TransformGroup();
				using (IEnumerator<Transform> enumerator = transformGroup.get_Children().GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						Transform current = enumerator.get_Current();
						transformGroup2.get_Children().Add(current.CloneTransform());
					}
				}
				return transformGroup2;
			}
			return transform.DeepCopy<Transform>();
		}
		public static bool TransformEquals(this Transform firstTransform, Transform secondTransform)
		{
			if (firstTransform == null && secondTransform == null)
			{
				return true;
			}
			if (firstTransform == null || secondTransform == null)
			{
				return false;
			}
			if (firstTransform == secondTransform)
			{
				return true;
			}
			TranslateTransform translateTransform = firstTransform as TranslateTransform;
			TranslateTransform translateTransform2 = secondTransform as TranslateTransform;
			if (translateTransform != null && translateTransform2 != null)
			{
				return TransformExtensions.TranslateTransformEquals(translateTransform, translateTransform2);
			}
			RotateTransform rotateTransform = firstTransform as RotateTransform;
			RotateTransform rotateTransform2 = secondTransform as RotateTransform;
			if (rotateTransform != null && rotateTransform2 != null)
			{
				return TransformExtensions.RotateTransformEquals(rotateTransform, rotateTransform2);
			}
			ScaleTransform scaleTransform = firstTransform as ScaleTransform;
			ScaleTransform scaleTransform2 = secondTransform as ScaleTransform;
			if (scaleTransform != null && scaleTransform2 != null)
			{
				return TransformExtensions.ScaleTransformEquals(scaleTransform, scaleTransform2);
			}
			SkewTransform skewTransform = firstTransform as SkewTransform;
			SkewTransform skewTransform2 = secondTransform as SkewTransform;
			if (skewTransform != null && skewTransform2 != null)
			{
				return TransformExtensions.SkewTransformEquals(skewTransform, skewTransform2);
			}
			MatrixTransform matrixTransform = firstTransform as MatrixTransform;
			MatrixTransform matrixTransform2 = secondTransform as MatrixTransform;
			if (matrixTransform != null && matrixTransform2 != null)
			{
				return TransformExtensions.MatrixTransformEquals(matrixTransform, matrixTransform2);
			}
			TransformGroup transformGroup = firstTransform as TransformGroup;
			TransformGroup transformGroup2 = secondTransform as TransformGroup;
			if (transformGroup != null && transformGroup2 != null)
			{
				return TransformExtensions.TransformGroupEquals(transformGroup, transformGroup2);
			}
			CompositeTransform compositeTransform = firstTransform as CompositeTransform;
			CompositeTransform compositeTransform2 = secondTransform as CompositeTransform;
			if (compositeTransform != null && compositeTransform2 != null)
			{
				return TransformExtensions.CompositeTransformEquals(compositeTransform, compositeTransform2);
			}
			TransformGroup transformGroup3 = new TransformGroup();
			transformGroup3.get_Children().Add(firstTransform);
			TransformGroup transformGroup4 = new TransformGroup();
			transformGroup4.get_Children().Add(secondTransform);
			return transformGroup3.get_Value() == transformGroup4.get_Value();
		}
		private static bool TranslateTransformEquals(TranslateTransform firstTransform, TranslateTransform secondTransform)
		{
			return firstTransform.get_X() == secondTransform.get_X() && firstTransform.get_Y() == secondTransform.get_Y();
		}
		private static bool RotateTransformEquals(RotateTransform firstTransform, RotateTransform secondTransform)
		{
			return firstTransform.get_Angle() == secondTransform.get_Angle() && firstTransform.get_CenterX() == secondTransform.get_CenterX() && firstTransform.get_CenterY() == secondTransform.get_CenterY();
		}
		private static bool ScaleTransformEquals(ScaleTransform firstTransform, ScaleTransform secondTransform)
		{
			return firstTransform.get_ScaleX() == secondTransform.get_ScaleX() && firstTransform.get_ScaleY() == secondTransform.get_ScaleY() && firstTransform.get_CenterX() == secondTransform.get_CenterX() && firstTransform.get_CenterY() == secondTransform.get_CenterY();
		}
		private static bool SkewTransformEquals(SkewTransform firstTransform, SkewTransform secondTransform)
		{
			return firstTransform.get_AngleX() == secondTransform.get_AngleX() && firstTransform.get_AngleY() == secondTransform.get_AngleY() && firstTransform.get_CenterX() == secondTransform.get_CenterX() && firstTransform.get_CenterY() == secondTransform.get_CenterY();
		}
		private static bool CompositeTransformEquals(CompositeTransform firstTransform, CompositeTransform secondTransform)
		{
			return firstTransform.get_CenterX() == secondTransform.get_CenterX() && firstTransform.get_CenterY() == secondTransform.get_CenterY() && firstTransform.get_Rotation() == secondTransform.get_Rotation() && firstTransform.get_ScaleX() == secondTransform.get_ScaleX() && firstTransform.get_ScaleY() == secondTransform.get_ScaleY() && firstTransform.get_SkewX() == secondTransform.get_SkewX() && firstTransform.get_SkewY() == secondTransform.get_SkewY() && firstTransform.get_TranslateX() == secondTransform.get_TranslateX() && firstTransform.get_TranslateY() == secondTransform.get_TranslateY();
		}
		private static bool TransformGroupEquals(TransformGroup firstTransform, TransformGroup secondTransform)
		{
			if (firstTransform.get_Children().get_Count() != secondTransform.get_Children().get_Count())
			{
				return false;
			}
			for (int i = 0; i < firstTransform.get_Children().get_Count(); i++)
			{
				if (!firstTransform.get_Children().get_Item(i).TransformEquals(secondTransform.get_Children().get_Item(i)))
				{
					return false;
				}
			}
			return true;
		}
		private static bool MatrixTransformEquals(MatrixTransform firstTransform, MatrixTransform secondTransform)
		{
			return firstTransform.get_Matrix() == secondTransform.get_Matrix();
		}
	}
}
